package com.qf;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/*
杨威
2021/9/11
11:25
*/
@WebServlet("/login")
public class service extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=gbk");
//        resp.setCharacterEncoding("utf-8");//设置响应编码格式为utf-8
//        resp.setHeader("Content-type","text/html;charset=utf-8");
        String userName = req.getParameter("userName");
        String passWord = req.getParameter("passWord");
//        byte[] bytes = userName.getBytes();
//        userName = new String(bytes, "utf-8");

        System.out.println(userName+"\t"+passWord);
        PrintWriter writer = resp.getWriter();
        writer.println("<html>");
        writer.println("    <head>");
//        writer.println("        <meta charset=\"utf-8\">");
        writer.println("        <title>登录界面</title>");
        writer.println("    </head>");
        writer.println("    <body>");
        if(userName.equals("gavin")&& passWord.equals("123456")){
            writer.println("    <h1 style=\"color: green\">登录成功</h1>");
        }else {
            writer.println("    <h1 style=\"color: red\">登录失败</h1>");
        }
        writer.println("    </body>");
        writer.println("</html>");
    }
}
